package com.duoduo.homework.h1;

import com.duoduo.algs4.util.ArrayUtil;

import edu.princeton.cs.introcs.StdIn;
import edu.princeton.cs.introcs.StdOut;
import edu.princeton.cs.introcs.StdRandom;

public class Dist {
	private static int SIDES = 6;
	private static double[] dist = new double[SIDES * 2 + 1];
	static {
		for (int i = 1; i <= SIDES; i++) {
			for (int j = 1; j <= SIDES; j++) {
				dist[i + j] += 1.0;
			}
		}
		for (int k = 2; k <= 2 * SIDES; k++) {
			dist[k] /= 36.0;
		}
	}

	public static double[] getDist() {
		return dist;
	}

	public static void printDist(double[] a, String name) {
		for (int k = 2; k <= 2 * SIDES; k++) {
			StdOut.printf("点数 %d 对应的概率为 %.3f\n", k, a[k]);
		}
		// DrawArray.DrawArray(a, 1.0 / 3, 0.5, name);
	}

	public static void testRandom() {
		int random;
		double[] dist;
		int N = 12;
		do {
			// 初始化数组
			dist = new double[SIDES * 2 + 1];
			for (int i = 0; i < N; i++) {
				random = StdRandom.uniform(2, 2 * SIDES + 1);
				dist[random] += 1.0;
			}
			// 除以得到概率
			for (int k = 2; k <= 2 * SIDES; k++) {
				dist[k] /= 1.0 * N;
			}
			StdOut.println("N为:" + N);
			// 输出
			printDist(dist, "两个骰子的概率 N为:" + N);

			N *= 1.2;

		} while (!StdIn.readString().equals("q"));

	}

	public static void main(String[] args) {
		// printDist(getDist());
		testRandom();
	}

}
